package cn.grf.datasource.flex.config;

import com.mybatisflex.core.FlexGlobalConfig;
import com.mybatisflex.core.audit.AuditManager;
import com.mybatisflex.spring.boot.MyBatisFlexCustomizer;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Configuration;

/**
 * @apiNote 
 * @author grf
 * @since 2025/5/6
 */
@Slf4j
@Configuration
@MapperScan(basePackages = "cn.grf.datasource.flex.*.mapper")
public class MybatisFlexConfig implements MyBatisFlexCustomizer {
    @Override
    public void customize(FlexGlobalConfig flexGlobalConfig) {
        // org.apache.ibatis.session.Configuration configuration = flexGlobalConfig.getConfiguration();
        // configuration.setMapUnderscoreToCamelCase(true);
        // flexGlobalConfig.setConfiguration(configuration);
        //开启审计功能
        AuditManager.setAuditEnable(true);

        //设置 SQL 审计收集器
        AuditManager.setMessageCollector(auditMessage ->
                log.info("{},{}ms", auditMessage.getFullSql()
                        , auditMessage.getElapsedTime())
        );
    }
}
